mod physics;
mod visual;
mod mover;
mod balloon;


use ggez::{Context, GameResult, GameError, graphics, glam::Vec2};


pub struct State{
    movers: Vec<Box<dyn mover::Mover>>
}

impl State{
    pub fn new(_ctx: &mut Context) -> State {
        let mut movers: Vec<Box<dyn mover::Mover>> = vec![];

        for _i in 0..20 {
            let location = Vec2{x: 0.0,y: 0.0};
            let mover = balloon::Balloon::new(location);
            movers.push(Box::new(mover));

        }
        State{ movers }
    }
}

impl ggez::event::EventHandler<GameError> for State {
    fn update(&mut self, ctx: &mut Context) -> GameResult {
        for mover in &mut self.movers {
            let fg = Vec2 {x: 0.0, y: 0.1};
            let fw = Vec2 {x: 0.01, y: 0.0};
            mover.apply_force(fg);
            mover.apply_force(fw);
            mover.update(ctx);
        }
        Ok(())
    }
    fn draw(&mut self, ctx: &mut Context) -> GameResult {
        let mut canvas = graphics::Canvas::from_frame(ctx, graphics::Color::WHITE);
        for mover in &mut self.movers {
            mover.display(ctx, &mut canvas);
        }
        canvas.finish(ctx)?;
        Ok(())
    }
}